// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#![no_implicit_prelude]
extern crate apps_script_type;
extern crate bytes;
extern crate serde;
extern crate serde_json;
extern crate serde_with;
extern crate std;
extern crate wkt;

mod debug;
mod deserialize;
mod serialize;

/// Calendar add-on manifest.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct CalendarAddOnManifest {
    /// Defines an endpoint that will be executed contexts that don't
    /// match a declared contextual trigger. Any cards generated by this function
    /// will always be available to the user, but may be eclipsed by contextual
    /// content when this add-on declares more targeted triggers.
    ///
    /// If present, this overrides the configuration from
    /// `addOns.common.homepageTrigger`.
    pub homepage_trigger: std::option::Option<apps_script_type::model::HomepageExtensionPoint>,

    /// Defines conference solutions provided by this add-on.
    pub conference_solution: std::vec::Vec<crate::model::ConferenceSolution>,

    /// An endpoint to execute that creates a URL to the add-on's settings page.
    pub create_settings_url_function: std::string::String,

    /// An endpoint to trigger when an event is opened (viewed/edited).
    pub event_open_trigger: std::option::Option<crate::model::CalendarExtensionPoint>,

    /// An endpoint to trigger when the open event is updated.
    pub event_update_trigger: std::option::Option<crate::model::CalendarExtensionPoint>,

    /// Define the level of data access when an event addon is triggered.
    pub current_event_access: crate::model::calendar_add_on_manifest::EventAccess,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl CalendarAddOnManifest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [homepage_trigger][crate::model::CalendarAddOnManifest::homepage_trigger].
    pub fn set_homepage_trigger<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<apps_script_type::model::HomepageExtensionPoint>,
    {
        self.homepage_trigger = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [homepage_trigger][crate::model::CalendarAddOnManifest::homepage_trigger].
    pub fn set_or_clear_homepage_trigger<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<apps_script_type::model::HomepageExtensionPoint>,
    {
        self.homepage_trigger = v.map(|x| x.into());
        self
    }

    /// Sets the value of [conference_solution][crate::model::CalendarAddOnManifest::conference_solution].
    pub fn set_conference_solution<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<crate::model::ConferenceSolution>,
    {
        use std::iter::Iterator;
        self.conference_solution = v.into_iter().map(|i| i.into()).collect();
        self
    }

    /// Sets the value of [create_settings_url_function][crate::model::CalendarAddOnManifest::create_settings_url_function].
    pub fn set_create_settings_url_function<T: std::convert::Into<std::string::String>>(
        mut self,
        v: T,
    ) -> Self {
        self.create_settings_url_function = v.into();
        self
    }

    /// Sets the value of [event_open_trigger][crate::model::CalendarAddOnManifest::event_open_trigger].
    pub fn set_event_open_trigger<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::CalendarExtensionPoint>,
    {
        self.event_open_trigger = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [event_open_trigger][crate::model::CalendarAddOnManifest::event_open_trigger].
    pub fn set_or_clear_event_open_trigger<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::CalendarExtensionPoint>,
    {
        self.event_open_trigger = v.map(|x| x.into());
        self
    }

    /// Sets the value of [event_update_trigger][crate::model::CalendarAddOnManifest::event_update_trigger].
    pub fn set_event_update_trigger<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::CalendarExtensionPoint>,
    {
        self.event_update_trigger = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [event_update_trigger][crate::model::CalendarAddOnManifest::event_update_trigger].
    pub fn set_or_clear_event_update_trigger<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::CalendarExtensionPoint>,
    {
        self.event_update_trigger = v.map(|x| x.into());
        self
    }

    /// Sets the value of [current_event_access][crate::model::CalendarAddOnManifest::current_event_access].
    pub fn set_current_event_access<
        T: std::convert::Into<crate::model::calendar_add_on_manifest::EventAccess>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.current_event_access = v.into();
        self
    }
}

impl wkt::message::Message for CalendarAddOnManifest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.apps.script.type.calendar.CalendarAddOnManifest"
    }
}

/// Defines additional types related to [CalendarAddOnManifest].
pub mod calendar_add_on_manifest {
    #[allow(unused_imports)]
    use super::*;

    /// An enum defining the level of data access event triggers require.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum EventAccess {
        /// Default value when nothing is set for EventAccess.
        Unspecified,
        /// METADATA gives event triggers the permission to access the metadata of
        /// events such as event id and calendar id.
        Metadata,
        /// READ gives event triggers access to all provided event fields including
        /// the metadata, attendees, and conference data.
        Read,
        /// WRITE gives event triggers access to the metadata of events and the
        /// ability to perform all actions, including adding attendees and setting
        /// conference data.
        Write,
        /// READ_WRITE gives event triggers access to all provided event fields
        /// including the metadata, attendees, and conference data and the ability to
        /// perform all actions.
        ReadWrite,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [EventAccess::value] or
        /// [EventAccess::name].
        UnknownValue(event_access::UnknownValue),
    }

    #[doc(hidden)]
    pub mod event_access {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl EventAccess {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::Metadata => std::option::Option::Some(1),
                Self::Read => std::option::Option::Some(3),
                Self::Write => std::option::Option::Some(4),
                Self::ReadWrite => std::option::Option::Some(5),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("UNSPECIFIED"),
                Self::Metadata => std::option::Option::Some("METADATA"),
                Self::Read => std::option::Option::Some("READ"),
                Self::Write => std::option::Option::Some("WRITE"),
                Self::ReadWrite => std::option::Option::Some("READ_WRITE"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for EventAccess {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for EventAccess {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for EventAccess {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::Metadata,
                3 => Self::Read,
                4 => Self::Write,
                5 => Self::ReadWrite,
                _ => Self::UnknownValue(event_access::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for EventAccess {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "UNSPECIFIED" => Self::Unspecified,
                "METADATA" => Self::Metadata,
                "READ" => Self::Read,
                "WRITE" => Self::Write,
                "READ_WRITE" => Self::ReadWrite,
                _ => Self::UnknownValue(event_access::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for EventAccess {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::Metadata => serializer.serialize_i32(1),
                Self::Read => serializer.serialize_i32(3),
                Self::Write => serializer.serialize_i32(4),
                Self::ReadWrite => serializer.serialize_i32(5),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for EventAccess {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<EventAccess>::new(
                ".google.apps.script.type.calendar.CalendarAddOnManifest.EventAccess",
            ))
        }
    }
}

/// Defines conference related values.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct ConferenceSolution {
    /// Required. The endpoint to call when ConferenceData should be created.
    pub on_create_function: std::string::String,

    /// Required. IDs should be unique across ConferenceSolutions within one
    /// add-on, but this is not strictly enforced. It is up to the add-on developer
    /// to assign them uniquely, otherwise the wrong ConferenceSolution may be
    /// used when the add-on is triggered. While the developer may change the
    /// display name of an add-on, the ID should not be changed.
    pub id: std::string::String,

    /// Required. The display name of the ConferenceSolution.
    pub name: std::string::String,

    /// Required. The URL for the logo image of the ConferenceSolution.
    pub logo_url: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl ConferenceSolution {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [on_create_function][crate::model::ConferenceSolution::on_create_function].
    pub fn set_on_create_function<T: std::convert::Into<std::string::String>>(
        mut self,
        v: T,
    ) -> Self {
        self.on_create_function = v.into();
        self
    }

    /// Sets the value of [id][crate::model::ConferenceSolution::id].
    pub fn set_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.id = v.into();
        self
    }

    /// Sets the value of [name][crate::model::ConferenceSolution::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }

    /// Sets the value of [logo_url][crate::model::ConferenceSolution::logo_url].
    pub fn set_logo_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.logo_url = v.into();
        self
    }
}

impl wkt::message::Message for ConferenceSolution {
    fn typename() -> &'static str {
        "type.googleapis.com/google.apps.script.type.calendar.ConferenceSolution"
    }
}

/// Common format for declaring a calendar add-on's triggers.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct CalendarExtensionPoint {
    /// Required. The endpoint to execute when this extension point is
    /// activated.
    pub run_function: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl CalendarExtensionPoint {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [run_function][crate::model::CalendarExtensionPoint::run_function].
    pub fn set_run_function<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.run_function = v.into();
        self
    }
}

impl wkt::message::Message for CalendarExtensionPoint {
    fn typename() -> &'static str {
        "type.googleapis.com/google.apps.script.type.calendar.CalendarExtensionPoint"
    }
}
